

let mysqlModule = require("mysql");

let connection = null;

class mysql {


   

    query(sql, value) {

        let promise = new Promise(function (resolve, reject) {

            let connection=mysqlModule.createConnection({ host: '127.0.0.1', user: 'root', password: '123456', database: 'yiqing' });
            connection.connect();
            /**
             * 推荐使用占位符方式查询，占位符可以防止 sql注入 占了 80%漏洞都是sql
             */
            connection.query(sql, value, function (err, result) {

                if (err) {
                    console.log(err.message);
                    //reject(err.message)
                } else {

                    //setTimeout(function () {//模拟数据的慢查询
                        resolve(result);
                    //},5000)
                   
                }

                connection.end();
            })


        })
        return promise;

    }


}

module.exports = mysql;